package cn.com.guage.dtm.stat.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.guage.dtm.common.annotation.Log;
import cn.com.guage.dtm.common.enums.BusinessType;
import cn.com.guage.dtm.stat.domain.StatDataExplore;
import cn.com.guage.dtm.stat.service.IStatDataExploreService;
import cn.com.guage.dtm.common.core.controller.BaseController;
import cn.com.guage.dtm.common.core.domain.AjaxResult;
import cn.com.guage.dtm.common.utils.poi.ExcelUtil;
import cn.com.guage.dtm.common.core.page.TableDataInfo;

/**
 * 数据探索Controller
 * 
 * @author yangdechao
 * @date 2021-06-22
 */
@Controller
@RequestMapping("/stat/explore")
public class StatDataExploreController extends BaseController
{
    private String prefix = "stat/explore";

    @Autowired
    private IStatDataExploreService statDataExploreService;

    @RequiresPermissions("stat:explore:view")
    @GetMapping()
    public String explore()
    {
        return prefix + "/explore";
    }

    /**
     * 查询数据探索列表
     */
    @RequiresPermissions("stat:explore:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StatDataExplore statDataExplore)
    {
        startPage();
        List<StatDataExplore> list = statDataExploreService.selectStatDataExploreList(statDataExplore);
        return getDataTable(list);
    }

    /**
     * 导出数据探索列表
     */
    @RequiresPermissions("stat:explore:export")
    @Log(title = "数据探索", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StatDataExplore statDataExplore)
    {
        List<StatDataExplore> list = statDataExploreService.selectStatDataExploreList(statDataExplore);
        ExcelUtil<StatDataExplore> util = new ExcelUtil<StatDataExplore>(StatDataExplore.class);
        return util.exportExcel(list, "数据探索数据");
    }

    /**
     * 新增数据探索
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据探索
     */
    @RequiresPermissions("stat:explore:add")
    @Log(title = "数据探索", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StatDataExplore statDataExplore)
    {
        return toAjax(statDataExploreService.insertStatDataExplore(statDataExplore));
    }

    /**
     * 修改数据探索
     */
    @GetMapping("/edit/{exploreId}")
    public String edit(@PathVariable("exploreId") Long exploreId, ModelMap mmap)
    {
        StatDataExplore statDataExplore = statDataExploreService.selectStatDataExploreById(exploreId);
        mmap.put("statDataExplore", statDataExplore);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据探索
     */
    @RequiresPermissions("stat:explore:edit")
    @Log(title = "数据探索", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StatDataExplore statDataExplore)
    {
        return toAjax(statDataExploreService.updateStatDataExplore(statDataExplore));
    }

    /**
     * 删除数据探索
     */
    @RequiresPermissions("stat:explore:remove")
    @Log(title = "数据探索", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(statDataExploreService.deleteStatDataExploreByIds(ids));
    }
    
    @RequiresPermissions("stat:explore:showExploreDetailPage")
  	@GetMapping("/showExploreDetailPage/{exploreId}")
  	public String showExploreDetailPage(@PathVariable("exploreId") Long exploreId, ModelMap mmap) {
  		mmap.put("exploreId", exploreId);
  		return prefix + "/explore-detail-table-list";
  	}
}
